﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ExpressionLanguage;

namespace Example1
{
    class Program
    {
        static void Main(string[] args)
        {
            // This example will simply show how to print out a Hello World string with access variable in both script and also
            // C# code. Anyway, if you just want to use the expression language as a fancier way to initialize configuration
            // data. Definitely you can . 

            // 1. Initialize a global function object and also a stack object that can be used as a shared data object between
            // C# code and script code. All the interaction is done based on these 2 objects.
            ExpressionInterpreter.ExecutionStack stack = new ExpressionInterpreter.ExecutionStack();
            ExpressionInterpreter.GlobalFunction function = new ExpressionInterpreter.GlobalFunction();
            // 2. In order to have some default function, we should load some basic library. 
            // The library code is pretty easy to understand, indeed you only need to know 3-6 APIs then you can do everything with it.
            CoreLibrary.LoadLibrary(function, stack);
            MathLibrary.LoadLibrary(function, stack);
            StringLibrary.LoadLibrary(function, stack);
            
            // 3. Since it is a fancier hello world. I first set a reference to a string has value "Hello".
            stack.AddString("Hello", "Hello");
            // 4. Write the script
            string script = "World=\"World\";print(Hello,\" \",World,\"!\");";

            ErrorCollector ret = ExpressionInterpreter.Execute(script, function, stack);
                
            // 5. See Hello World on screen :)
            return;
        }
    }
}
